Skip to content

fix(skills): treat YAML and UTF-8 skill resources as text - #1915

Open
100lalitahegde-eng wants to merge 1 commit into
google:mainfrom
100lalitahegde-eng:fix-1893-yaml-skill-mime
Open

100lalitahegde-eng wants to merge 1 commit into
google:mainfrom
100lalitahegde-eng:fix-1893-yaml-skill-mime

Conversation

@100lalitahegde-eng

@100lalitahegde-eng 100lalitahegde-eng commented Nov 24, 2026 •

Copy link
Copy Markdown

Fixes #1893.

LoadSkillResourceTool.createResult decided whether a resource was text from its guessed MIME type. The JDK has no mapping for many text formats (.yml, .yaml, .toml, .ini, .properties, .sql, .ts, .kt, ...), so those files fell through to application/octet-stream and were sent as a binary Part, which Vertex AI rejects.

This change:

  • Maps .yml and .yaml to application/yaml, the same way .sh/.bash are already special-cased. Extension checks are case-insensitive.
  • When both the name-based and stream-based guesses return null, strictly decodes the bytes as UTF-8: valid UTF-8 is returned as text/plain, anything else stays application/octet-stream. This matches ADK Python and ADK Kotlin in treating valid UTF-8 as text, except that Java applies that fallback only when JDK MIME guessing returns null, so JDK-mapped non-text/ types like .svg and .tex stay binary.

Testing: ./mvnw -pl core test -Dtest=LoadSkillResourceToolTest,LoadSkillResourceMixedPartsRegressionTest: all pass, including new cases for .yml, .yaml, assets/CONFIG.YAML, assets/config.toml (with multi-byte UTF-8, name = "café"), a non-UTF-8 references/binary.dat (0xFF 0xFE 0x80), and a truncated UTF-8 sequence in references/truncated.dat ({'a', 0xC3}). Formatted with google-java-format 1.28.0.

@hemasekhar-p hemasekhar-p self-assigned this Nov 24, 2026
@hemasekhar-p

Copy link
Copy Markdown
Contributor

Hi @100lalitahegde-eng, Thank you for your contribution and for taking the time to submit this pull request. Our team is currently reviewing your changes, and we will reach out if we need any further information.

@kvmilos kvmilos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change Fixes #1893 to Part of #1893 (or Refs #1893) if we keep this PR scoped to .yml/.yaml? Issue #1893 asks for valid UTF-8 text regardless of extension, so we don't want the remaining extensions lost when the issue closes.

Comment on lines +216 to +226
String contentType;
if (resourcePath.endsWith(".sh") || resourcePath.endsWith(".bash")) {
// guessContentTypeFromName would return application/x-shar
contentType = "application/x-sh";
} else if (resourcePath.endsWith(".yml") || resourcePath.endsWith(".yaml")) {
// The JVM does not map these extensions, so the name-based guess is null
// and we would otherwise fall back to application/octet-stream.
contentType = "application/yaml";
} else {
contentType = guessContentTypeFromName(resourcePath);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we fall back to strict UTF-8 decoding before application/octet-stream when both guesses return null?

Handling only .yml and .yaml still leaves other text formats missing from the JDK's MIME table (.toml, .ini, .properties, .sql, .ts, .kt, etc.) falling back to application/octet-stream and hitting the same Vertex AI 400. ADK Python and ADK Kotlin instead try a strict UTF-8 decode and treat valid UTF-8 as text.

Note that references/binary.dat in the test uses {0, 1, 2, 3}, which is valid UTF-8, so it would need non-UTF-8 bytes (or a NUL check) if we go that route. If you prefer to keep this PR scoped to YAML, that's fine too; we can leave #1893 open for the rest.

if (resourcePath.endsWith(".sh") || resourcePath.endsWith(".bash")) {
// guessContentTypeFromName would return application/x-shar
contentType = "application/x-sh";
} else if (resourcePath.endsWith(".yml") || resourcePath.endsWith(".yaml")) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we keep the extension check, could you match on a lowercased extension (such as Ascii.toLowerCase(Files.getFileExtension(resourcePath)) with a small map, or Ascii.toLowerCase(resourcePath)) and add an uppercase test case in LoadSkillResourceToolTest?

endsWith(".yml") || endsWith(".yaml") is case-sensitive, so uppercase extensions like assets/CONFIG.YAML or assets/config.YML still fall through to application/octet-stream (the JDK lowercases extensions internally, but has no YAML entry).

@kvmilos kvmilos added the waiting on author Awaiting response from author. Failing that, maintainers will eventually closed it as stale. label Nov 30, 2026
@100lalitahegde-eng

Copy link
Copy Markdown
Author

@kvmilos Thanks for the review. I went with the strict UTF-8 fallback: when both MIME guesses are null, valid UTF-8 is now returned as text/plain. That covers unmapped extensions such as .toml, .ini, .properties, .sql, .ts, and .kt, so I kept Fixes #1893.

Also in the follow-up commit:

  • Extension checks use Ascii.toLowerCase(Files.getFileExtension(...)), with a test for assets/CONFIG.YAML
  • references/binary.dat now uses non-UTF-8 bytes (0xFF 0xFE 0x80)
  • The YAML comment is one line

@kvmilos kvmilos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. The UTF-8 fallback, case-insensitive extension check, and comment cleanup look good. A few small things before we merge:

  • Update the PR title (which becomes the changelog headline) to cover the general UTF-8 fallback, e.g., fix(skills): treat YAML and UTF-8 skill resources as text.
  • Qualify "This matches ADK Python and ADK Kotlin" in the PR description to note that Java uses the UTF-8 fallback only when JDK MIME guessing returns null, so JDK-mapped non-text/ types like .svg and .tex stay binary.
  • Squash the two commits into one so the single-commit check passes once CI runs.

Comment on lines +161 to +178
@Test
public void call_loadSkillResourceTool_unknownTextExtension_success() {
LoadSkillResourceTool loadSkillResourceTool =
new LoadSkillResourceTool(createTestSkillSource());
Map<String, Object> response =
loadSkillResourceTool
.runAsync(
ImmutableMap.of("skill_name", "test-skill", "file_path", "assets/config.toml"),
createToolContext())
.blockingGet();

assertThat(response)
.containsExactly(
"skill_name", "test-skill",
"file_path", "assets/config.toml",
"mime_type", "text/plain",
"content", "id = \"a\"\nname = \"b\"\n");
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assets/config.toml is plain 7-bit ASCII and references/binary.dat fails on byte 0, so swapping UTF_8 for US_ASCII would still pass every test. Could you include multi-byte UTF-8 characters (for example, "name = \"café\"\n") in the .toml test, and add a binary case with a valid UTF-8 prefix followed by a truncated sequence (for example, {'a', (byte) 0xC3})?

Fixes google#1893.

LoadSkillResourceTool.createResult left many text formats untyped
(.yml, .yaml, .toml, .ini, and others), so they fell back to
application/octet-stream and were sent as binary parts, which Vertex
AI rejects.

Map .yml and .yaml to application/yaml (case-insensitive, like .sh).
When both MIME guesses are null, strictly decode as UTF-8 and treat
valid UTF-8 as text/plain.
@100lalitahegde-eng 100lalitahegde-eng changed the title fix(skills): treat YAML skill resources as text fix(skills): treat YAML and UTF-8 skill resources as text Dec 1, 2026
@100lalitahegde-eng

Copy link
Copy Markdown
Author

@kvmilos Thanks. I updated the title, qualified the Python/Kotlin note (UTF-8 fallback only when both JDK guesses are null, so .svg and .tex stay binary), added multi-byte UTF-8 in the .toml test and a truncated-sequence binary case ({'a', 0xC3}), and squashed to one commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs review waiting on author Awaiting response from author. Failing that, maintainers will eventually closed it as stale.

Projects

None yet

3 participants